using Sirenix.OdinInspector;
using UnityEngine;

namespace YDExtendTool.Scripts
{
    public class Singleton<T> : MonoBehaviour where T : Singleton<T>
    {
        private static T _instance;

        public static T Instance
        {
            get
            {
                if (_instance == null)
                {
                    string name = typeof(T).ToString();
                    GameObject gobj = GameObject.Find(name);
                    if (null == gobj)
                    {
                        gobj = new GameObject(typeof(T).ToString());
                    }

                    _instance = gobj.GetComponent<T>();
                    if (null == _instance)
                    {
                        _instance = gobj.AddComponent<T>();
                    }
                    _instance.Init();
                }
                return _instance;
            }
        }

        protected virtual void Init()
        {
            
        }
    }
}
